package com.monster.dao;

import java.sql.ResultSet;
import java.sql.SQLException;

public class UserFocusDaoImpl extends BaseDao implements UserFocusDao {
    ResultSet rs = null;
    int result = 0;
    //查询某收藏是否存在
    /**
     * 通过用户id,收藏类型，收藏对应的ID
     * @param userId
     * @param focusType
     * @param focusId
     * @return 如果存在就返回1
     */
    @Override
    public int getFocusCountByID(Long userId, int focusType, Long focusId) {
        Object[] params = {userId,focusType,focusId};
        String sql = "SELECT * FROM user_focus WHERE user_id = ? AND focus_type = ? AND focus_id = ?";
        rs = this.executeQuery(sql, params);
        try {
            while (rs.next()) {
                result = 1;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return result;
    }
    //添加收藏
    /**
     * 通过用户id,收藏类型，收藏对应的ID
     * @param userId
     * @param focusType
     * @param focusId
     * @return 添加成功返回1
     */

    @Override
    public int addFocusByID(Long userId, int focusType, Long focusId) {
        Object[] params = {userId,focusType,focusId};
        String sql = "INSERT INTO user_focus VALUES (DEFAULT,?,?,?)";
        result = this.executeUpdate(sql,params);
        return result;
    }

    /**
     * 通过用户id,收藏类型，收藏对应的ID
     * @param userId
     * @param focusType
     * @param focusId
     * @return 添加成功返回1
     */
    @Override
    public int deleteFocusById(Long userId, int focusType, Long focusId) {
        Object[] params = {userId,focusType,focusId};
        String sql = "DELETE FROM user_focus WHERE user_id = ? AND focus_type = ? AND focus_id = ?";
        result = this.executeUpdate(sql,params);
        return result;
    }
}
